#include "Character.h"
#include "CharacterWrapper.h"

#include "lua.hpp"
#include "luawrapper.hpp"

static Character* Character_new(lua_State* L)
{
	const char* name = luaL_checkstring(L, 1);
	int hp = luaL_checknumber(L, 2);
	return new Character(name, hp);
}

static int Character_getName(lua_State* L)
{
	Character* character = luaW_check<Character>(L, 1);
	lua_pushstring(L, character->getName());
	return 1;
}


static int Character_getHealth(lua_State* L)
{
	Character* character = luaW_check<Character>(L, 1);
	lua_pushnumber(L, character->getHealth());
	return 1;
}

static int Character_setHealth(lua_State* L)
{
	Character* character = luaW_check<Character>(L, 1);
	int hp = luaL_checknumber(L, 2);
	character->setHealth(hp);
	return 0;
}


static luaL_Reg Character_table[] =
{
	{ NULL, NULL }
};

static luaL_Reg Character_metatable[] =
{
	{ "getName", Character_getName },
	{ "getHealth", Character_getHealth },
	{ "setHealth", Character_setHealth },
	{ NULL, NULL }
};

int luaopen_Character(lua_State* L)
{
	luaW_register<Character>(L, "Character", Character_table, Character_metatable, Character_new);
	return 1;
}